define(['common','jquery','vue'], function (common, $, Vue) {
    const Controller = {
        index:function (){
            const {createApp,  ref, onMounted} = Vue
            const app = createApp({
                setup(){
                    const list = ref({
                        total:0,
                        rows:[],
                        page:1,
                        limit:10,
                        seachObj:[
                            {
                                label:'是否树状',
                                type:'select',
                                name:"isTree",
                                options:[
                                    {
                                        label:'是',
                                        value:1
                                    },
                                    {
                                        label:'否',
                                        value:0
                                    }
                                ],
                                value:1,
                                is_show:false
                            },
                            {
                                label:'排序',
                                type:'input',
                                name:"sort",
                                value:'pid',
                                is_show:false
                            },
                            {
                                label:'排序',
                                type:'input',
                                name:"order",
                                value:'desc',
                                is_show:false
                            }
                        ]
                    })
                    const getIndexData = ()=>{
                        common.loadingIndexData(list.value).then(res=>{
                            if(res.code==1){
                                list.value.rows = res.data.rows
                                list.value.total = res.data.total
                            }
                        })
                    }
                    onMounted(()=>{
                        getIndexData()
                        // window.updateMenu = function (){
                        //     if(parent.window.updateMenu){
                        //         parent.window.updateMenu()
                        //     }
                        // }
                    })
                    const changePage = (page)=>{
                        list.value.page = page
                        getIndexData()
                    }
                    const changeSize = (size)=>{
                        list.value.limit = size
                        getIndexData()
                    }
                    const refresh = ()=>{
                        getIndexData()
                    }
                    const changeSwitch = async (row,pk,field)=>{
                        await common.changeSwitch(row,pk,field);
                        parent.window.updateMenu()
                    }
                    const del = async (row)=>{
                        await common.del(row)
                        parent.window.updateMenu()
                    }
                    common.refresh = refresh
                    return {
                        list,
                        changePage,
                        changeSize,
                        common:common,
                        changeSwitch,
                        del
                    }
                }
            })
            common.load(app)
            app.mount('#app')
        },
        add:function (){
            const {createApp,  ref, onMounted} = Vue
            const app = createApp({
                setup(){
                    const form = ref({
                        pid:'',
                        name:"",
                        module:"",
                        route:"",
                        title:"",
                        icon:"",
                        ismenu:0,
                        remark:"",
                        status:1
                    })
                    const allList = ref(Config.allList)
                    const allAddons = ref(Config.allAddons)
                    const onAddSubmit = async (form)=>{
                        await common.onAddSubmit(form)
                        // console.log(parent.parent.window)
                        parent.parent.window.updateMenu()
                    }
                    return {
                        form,
                        common:common,
                        allList,
                        allAddons,
                        onAddSubmit
                    }
                }
            })
            common.load(app)
            app.mount('#app')
        },
        edit:function (){
            const {createApp,  ref, onMounted} = Vue
            const app = createApp({
                setup(){
                    const form = ref({
                        pid:Config.row.pid,
                        name:Config.row.name,
                        module:Config.row.module,
                        route:Config.row.route,
                        title:Config.row.title,
                        icon:Config.row.icon,
                        ismenu:Config.row.ismenu,
                        remark:Config.row.remark,
                        status:Config.row.status
                    })
                    console.log(Config.row)
                    const allList = ref(Config.allList)
                    const allAddons = ref(Config.allAddons)
                    const onEditSubmit = async (form)=>{
                        await common.onEditSubmit(form)
                        parent.parent.window.updateMenu()
                    }
                    return {
                        form,
                        common:common,
                        allList,
                        allAddons,
                        onEditSubmit
                    }
                }
            })
            common.load(app)
            app.mount('#app')
        }
    }
    return Controller
})